


# to load data
library(rio)

# to process data
library(tidyverse)


# load data about laws 
laws <- import("list_laws.csv")



#### GENERATE TABLE 2
# load data
load("covariates.RData")

imf_program_participation <- covariates %>%
  group_by(iso3c) %>%
  summarise(imf_program_sum = sum(imf_program))

gdp <- covariates %>%
  filter(!is.na(gdp_pc_constant)) %>%
  group_by(iso3c) %>%
  slice_max(year, n = 1) %>%
  select(iso3c,gdp_pc_constant)

rents <- covariates %>%
  filter(!is.na(resource_rents)) %>%
  group_by(iso3c) %>%
  slice_max(year, n = 1) %>%
  select(iso3c,resource_rents)

table2 <- imf_program_participation %>%
  full_join(gdp) %>%
  full_join(rents) %>%
  mutate(laws = ifelse(iso3c %in% laws$iso3c, "with_funds", "without_funds")) %>%
  group_by(laws) %>%
  summarise(imf_program_sum_mean = mean(imf_program_sum),
            gdp_pc_constant_mean = mean(gdp_pc_constant, na.rm = T)*1000,
            resource_rents_mean = mean(resource_rents),
            N = length(iso3c)) 
